home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_vga.arc / VGA64-L3.ASM < prev    next >
Assembly Source File  |  1988-04-03  |  2KB  |  107 lines

  1. ; *** Listing 3 ***
  2. ;
  3. ; Program that draws a diagonal line to illustrate the use of a
  4. ; Color Don't Care register setting of 0FFh to support fast
  5. ; read-modify-write operations to VGA memory in write mode 3 by
  6. ; drawing a diagonal line.
  7. ;
  8. ; Note: Works on VGAs only.
  9. ;
  10. ; By Michael Abrash 4/2/88
  11. ;
  12. stack    segment    word stack 'STACK'
  13.     db    512 dup (?)
  14. stack    ends
  15. ;
  16. VGA_SEGMENT    EQU    0a000h
  17. SCREEN_WIDTH    EQU    80    ;in bytes
  18. GC_INDEX    EQU    3ceh    ;Graphics Controller Index register
  19. SET_RESET    EQU    0    ;Set/Reset register index in GC
  20. ENABLE_SET_RESET EQU    1    ;Enable Set/Reset register index in GC
  21. GRAPHICS_MODE    EQU    5    ;Graphics Mode register index in GC
  22. COLOR_DONT_CARE    EQU    7    ;Color Don't Care register index in GC
  23. ;
  24. code    segment    word 'CODE'
  25.     assume    cs:code
  26. Start    proc    near
  27. ;
  28. ; Select graphics mode 12h.
  29. ;
  30.     mov    ax,12h
  31.     int    10h
  32. ;
  33. ; Select write mode 3 and read mode 1.
  34. ;
  35.     mov    dx,GC_INDEX
  36.     mov    al,GRAPHICS_MODE
  37.     out    dx,al
  38.     inc    dx
  39.     in    al,dx        ;VGA registers are readable, bless them!
  40.     or    al,00001011b    ;bit 3=1 selects read mode 1, and
  41.                 ; bits 1 & 0=11 selects write mode 3
  42.     jmp    $+2        ;delay between IN and OUT to same port
  43.     out    dx,al
  44.     dec    dx
  45. ;
  46. ; Set up set/reset to always draw in white.
  47. ;
  48.     mov    al,SET_RESET
  49.     out    dx,al
  50.     inc    dx
  51.     mov    al,0fh
  52.     out    dx,al
  53.     dec    dx
  54.     mov    al,ENABLE_SET_RESET
  55.     out    dx,al
  56.     inc    dx
  57.     mov    al,0fh
  58.     out    dx,al
  59.     dec    dx
  60. ;
  61. ; Set Color Don't Care to 0, so reads of VGA memory always return 0FFh.
  62. ;
  63.     mov    al,COLOR_DONT_CARE
  64.     out    dx,al
  65.     inc    dx
  66.     sub    al,al
  67.     out    dx,al
  68. ;
  69. ; Set up the initial memory pointer and pixel mask.
  70. ;
  71.     mov    ax,VGA_SEGMENT
  72.     mov    ds,ax
  73.     sub    bx,bx
  74.     mov    al,80h
  75. ;
  76. ; Draw 400 points on a diagonal line sloping down and to the right.
  77. ;
  78.     mov    cx,400
  79. DrawDiagonalLoop:
  80.     and    [bx],al    ;reads display memory, loading the latches,
  81.             ; then writes AL to the VGA. AL becomes the
  82.             ; bit mask, and set/reset provides the
  83.             ; actual data written
  84.     add    bx,SCREEN_WIDTH
  85.             ; point to the next scan line
  86.     ror    al,1    ;move the pixel mask one pixel to the right
  87.     adc    bx,0    ;advance to the next byte if the pixel mask wrapped
  88.     loop    DrawDiagonalLoop
  89. ;
  90. ; Wait for a key to be pressed to end, then return to text mode and
  91. ; return to DOS.
  92. ;
  93. WaitKeyLoop:
  94.     mov    ah,1
  95.     int    16h
  96.     jz    WaitKeyLoop
  97.     sub    ah,ah
  98.     int    16h    ;clear the key
  99.     mov    ax,3
  100.     int    10h    ;return to text mode
  101.     mov    ah,4ch
  102.     int    21h    ;done
  103. Start    endp
  104. code    ends
  105.     end    Start
  106.  
  107.